<?php

class MessageModel extends RelationModel {
	/*
	 * 定义关联关系 
	 */

	public $_link = array(
//		'User'=>array(
//			'mapping_type'=>BELONGS_TO,
//			'class_name'=>'User',
//			'foreign_key'=>'user_id',
//		),
//		'From'=>array(
//			'mapping_type'=> BELONGS_TO,
//			'class_name'=>'User',
//			'foreign_key'=>'from_id',
//		),

		'tweets' => array(
			'mapping_type' => BELONGS_TO,
			'class_name' => 'tweets',
			'foreign_key' => 'tweets_id',
			'condition' => 'status=1',
		),
		'reply' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'reply',
			'foreign_key' => 'message_id',
		),
	);
	/*
	 * 表单数据验证 
	 */
	protected $_validate = array(
		array('content', 'require', '请填写私信内容！'),
	);

	/*
	 * 数据自动完成 
	 */
	protected $_auto = array(
		//array('summary','getSummary',1,'callback'),
		array('create_time', 'time', 1, 'function'),
	);

	//获取内容节选
	function getSummary() {
		$content = $_POST['Content'];
		if (!empty($content)) {
			$summary = substr($content, 0, 200);
			return $summary;
		}
	}

	/*
	 * 表单项与字段的映射
	 */
}

?>
